﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;
using YArchitech.DataModel;
using YArchitech.LIB;

namespace YJKFurniture.LayoutFurnitures
{
	public partial class LayoutAlongWallForm : System.Windows.Forms.Form
	{
		public LayoutAlongWallForm()
		{
			this.InitializeComponent();
			//base.Icon = Resource.YArchitechIcon;
		}

		private void LayoutAlongWallForm_Load(object sender, EventArgs e)
		{
			this.InitUserSetting();
			this.m_nFurnitureNum = (int)this.nudFurnitureNum.Value;
			this.m_nFurnitureSpace = Convert.ToInt32(this.txtFurnitureSpace.Text);
			this.m_nDistanceToFace = Convert.ToInt32(this.txtDistanceToWallFace.Text);
			this.m_nDistanceToSide = Convert.ToInt32(this.txtDistanceToWallSide.Text);
		}

		private void SetUserData()
		{
			this.m_userSetting.ReloadFile();
			this.m_userSetting.WriteValue("FurnitureLayout", "AlongWallNum", this.nudFurnitureNum.Value.ToString());
			this.m_userSetting.WriteValue("FurnitureLayout", "AlongWallSpace", this.txtFurnitureSpace.Text);
			this.m_userSetting.WriteValue("FurnitureLayout", "AlongWallDistanceToFace", this.txtDistanceToWallFace.Text);
			this.m_userSetting.WriteValue("FurnitureLayout", "AlongWallDistanceToSide", this.txtDistanceToWallSide.Text);
		}

		private void InitUserSetting()
		{
			try
			{
				string value = this.m_userSetting.GetValue("FurnitureLayout", "AlongWallNum");
				if (value == null || value == "")
				{
					this.nudFurnitureNum.Value = this.m_nFurnitureNum;
				}
				else
				{
					this.nudFurnitureNum.Value = Convert.ToInt32(value);
				}
				string value2 = this.m_userSetting.GetValue("FurnitureLayout", "AlongWallSpace");
				if (value2 == null || value2 == "")
				{
					this.txtFurnitureSpace.Text = this.m_nFurnitureSpace.ToString();
				}
				else
				{
					this.txtFurnitureSpace.Text = value2;
				}
				string value3 = this.m_userSetting.GetValue("FurnitureLayout", "AlongWallDistanceToFace");
				if (value3 == null || value3 == "")
				{
					this.txtDistanceToWallFace.Text = this.m_nDistanceToFace.ToString();
				}
				else
				{
					this.txtDistanceToWallFace.Text = value3;
				}
				string value4 = this.m_userSetting.GetValue("FurnitureLayout", "AlongWallDistanceToSide");
				if (value4 == null || value4 == "")
				{
					this.txtDistanceToWallSide.Text = this.m_nDistanceToSide.ToString();
				}
				else
				{
					this.txtDistanceToWallSide.Text = value4;
				}
			}
			catch
			{
			}
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			try
			{
				this.m_nFurnitureNum = (int)this.nudFurnitureNum.Value;
				this.m_nFurnitureSpace = Convert.ToInt32(this.txtFurnitureSpace.Text);
				this.m_nDistanceToFace = Convert.ToInt32(this.txtDistanceToWallFace.Text);
				this.m_nDistanceToSide = Convert.ToInt32(this.txtDistanceToWallSide.Text);
			}
			catch
			{
			}
		}

		private void nudFurnitureNum_ValueChanged(object sender, EventArgs e)
		{
			if ((int)this.nudFurnitureNum.Value < 1)
			{
				YJKMessageBox.Show("设备数量必须大于等于1", MessageBoxButtons.OK);
				this.nudFurnitureNum.Value = this.m_nFurnitureNum;
				return;
			}
			this.m_nFurnitureNum = (int)this.nudFurnitureNum.Value;
		}

		private void txtFurnitureSpace_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.m_nFurnitureSpace = Convert.ToInt32(this.txtFurnitureSpace.Text);
			}
			catch
			{
				this.txtFurnitureSpace.Text = this.m_nFurnitureSpace.ToString();
			}
		}

		private void txtDistanceToWallFace_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.m_nDistanceToFace = Convert.ToInt32(this.txtDistanceToWallFace.Text);
			}
			catch
			{
				this.txtDistanceToWallFace.Text = this.m_nDistanceToFace.ToString();
			}
		}

		private void txtDistanceToWallSide_TextChanged(object sender, EventArgs e)
		{
			try
			{
				this.m_nDistanceToSide = Convert.ToInt32(this.txtDistanceToWallSide.Text);
			}
			catch
			{
				this.txtDistanceToWallSide.Text = this.m_nDistanceToSide.ToString();
			}
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void LayoutAlongWallForm_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				base.Close();
			}
		}

		private void LayoutAlongWallForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult != DialogResult.OK)
			{
				return;
			}
			this.SetUserData();
		}

		public int m_nFurnitureNum = 3;

		public int m_nFurnitureSpace = 1200;

		public int m_nDistanceToFace = 100;

		public int m_nDistanceToSide = 450;

		private UserSetting m_userSetting = new UserSetting();
	}
}
